package com.moon.controller;

import com.github.pagehelper.PageInfo;
import com.moon.dao.TAuctionMapper;
import com.moon.dao.TProductMapper;
import com.moon.entity.TAuction;
import com.moon.entity.TAuctionItem;
import com.moon.entity.TProduct;
import com.moon.service.TAuctionItemService;
import com.moon.utils.ProductUtils;
import com.moon.vo.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/auction")
@RestController
public class AuctionController {
    @Autowired
    private TAuctionMapper auctionMapper;

    @Autowired
    private TProductMapper tProductMapper;

    @Autowired
    private TAuctionItemService tAuctionItemService;

    @RequestMapping("queryTProduct")
    public ProductVo queryTProduct(@RequestParam("tProductId")Long tProductId){
        TProduct tProduct = tProductMapper.selectByPrimaryKey(tProductId);
        return ProductUtils.getList(tProduct);
    }

    @RequestMapping("queryTAuction")
    public TAuction queryTAuction(@RequestParam("id")Long id){
        TAuction tAuction = auctionMapper.selectByPrimaryKey(id);
        return tAuction;
    }

    @RequestMapping("queryTAuctionItem")
    public List<TAuctionItem> queryTAuctionItem(@RequestParam("id")Long id, @RequestParam("currentPage")Integer currentPage, @RequestParam("pageSize")Integer pageSize){
        List<TAuctionItem> tAuctionItems = tAuctionItemService.queryTAuctionItem(id,currentPage,pageSize);
        return tAuctionItems;
    }



    /**
     * 获取竞拍室下的所有竞拍记录item
     * @param auctionId
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping("/getItemByAuctionId")
    public PageInfo<TAuctionItem> getItemByAuctionId(@RequestParam("id") long auctionId , @RequestParam(name = "currentPage",defaultValue = "1") Integer pageNo , @RequestParam(name="pageSize",defaultValue = "6")Integer pageSize) {
        return tAuctionItemService.getItemByAuctionId(auctionId, pageNo, pageSize);
    }



}
